var t, e = getApp();

Page({
    data: {
        qrcode: "",
        vedioSrc: "",
        adShow: !1,
        hotel_id: "",
        storeBalance: !1
    },
    onLoad: function(t) {
        if ("storeBalance" == t.name) return this.setData({
            store_id: t.store_id,
            name: t.name,
            storeBalance: !0
        }), wx.setNavigationBarTitle({
            title: "我的二维码"
        }), void this.getBalanceCode();
        e._isTextEmpty(t.hotel_id) ? this.getQrcode() : (this.setData({
            hotel_id: t.hotel_id
        }), this.getHotelData());
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        this.closeTimeInterval();
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getBalanceCode: function() {
        var t = this, a = e.getNetAddresss("plugin.store-cashier.frontend.store.balance.agent.getQrCode");
        e._getNetWork({
            url: a,
            data: {
                store_id: this.data.store_id
            },
            success: function(e) {
                var a = e.data;
                1 == a.result && t.setData({
                    qrcode: a.data.qr_code,
                    adShow: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getQrcode: function() {
        var t = this, a = e.getNetAddresss("plugin.store-cashier.frontend.cashier.QrCode");
        e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 == a.result && (t.setData({
                    qrcode: a.data.small_url,
                    adShow: 1 == a.data.audio_open
                }), 1 == a.data.audio_open && t.openTime(a.data.store_id));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    openTime: function(a) {
        var o = this;
        t = setInterval(function() {
            var t = o, n = e.getNetAddresss("plugin.store-cashier.frontend.cashier.voice-broadcast.index");
            n += "&store_id=" + a, wx.request({
                url: n,
                data: {},
                header: {
                    "Content-Type": "application/json",
                    Accept: "application/json"
                },
                success: function(e) {
                    1 == e.data.result && (t.setData({
                        vedioSrc: e.data.data.url
                    }), console.log(e.data.data.url), t.data.vedioSrc && (t.audioCtx = wx.createAudioContext("yp"), 
                    t.audioCtx.play()));
                },
                fail: function(t) {},
                complete: function(t) {}
            });
        }, 5e3);
    },
    closeTimeInterval: function() {
        clearInterval(t);
    },
    getHotelData: function() {
        var t = this, a = e.getNetAddresss("plugin.hotel.frontend.cashier.qr-code.index");
        e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 == a.result && t.setData({
                    qrcode: a.data.url
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});